<%-- 
    Document   : listFiles
    Created on : 11 juin 2014, 15:12:57
    Author     : noelladana
--%>

<%@page import="com.cassiopae.util.CassiopaeDumpConstant"%>
<%@page import="com.cassiopae.util.CassiopaeDumpUtil"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.cassiopae.entity.User"%>
<%@page import="com.cassiopae.entity.Profile"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
		ObjSelec = null;
		

		function SelectLigne(obj)
		{
			var idLigne=obj.id;
			obj.className="selection";
			if (ObjSelec!=null)
			{
				ObjSelec.className = "defaut";
				ObjSelec = obj;
			}
			else
			{
				ObjSelec = obj;
			}
		}
		function verif_bouton()
		{
			btn1=document.form1.getElementById("creer") ; 
			btn1.disabled=false;
		}

		function UpdateIDProfile(profileID)
		{
     		document.getElementById("ProfileID").value = profileID;
		}

		function deleteProfile(profileID)
		{
     		document.getElementById("deleteProfileID").value = profileID;
		}
		
		function environmentDmpClick(){
			if( document.getElementById("environmentDmpBackFrontID").checked ){
				document.getElementById("hiddenFormID").style.display = 'block';
			}else{
				document.getElementById("hiddenFormID").style.display = 'none';
				document.getElementById("OtherSourceSchemaInput").value = '';
				document.getElementById("impSchemaSelected").setSelectedIndex = 0;
				
			}
		}

		
	</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Liste Dump</title>

<!-- Core CSS - Include with every page -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.css" rel="stylesheet">

<!-- Page-Level Plugin CSS - Tables -->
<link href="css/plugins/dataTables/dataTables.bootstrap.css"
	rel="stylesheet">

<!-- SB Admin CSS - Include with every page -->
<link href="css/sb-admin.css" rel="stylesheet">



</head>

<body>

	<div id="wrapper">

		<nav class="navbar navbar-default navbar-fixed-top" role="navigation"
			style="margin-bottom: 0">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle" data-toggle="collapse"
					data-target=".sidebar-collapse">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a class="navbar-brand">Welcome to CASSIOPAE DUMP</a>
			</div>

			<!-- /.dropdown -->
			<ul class="nav navbar-top-links navbar-right">
				<li class="dropdown"></li>
				<!-- /.dropdown -->

				<li class="dropdown"><a class="dropdown-toggle"
					data-toggle="dropdown" href="#"> <i class="fa fa-user fa-fw"></i>
						<i class="fa fa-caret-down"></i>
				</a>
					<ul class="dropdown-menu dropdown-user">
						<li><a href="#"><i class="fa fa-user fa-fw"></i> <%
 	User user = (User) request.getSession().getAttribute("user");
 %> <label><%=user.getPrenom()+" "%><%=user.getNom()%></label> </a></li>
						<!-- li><a style="text-decoration: none;" href="#"
							data-toggle="modal" data-target="#myResetPwd" name="creer"
							id="creer" onload="verif_bouton();"><i
								class="fa fa-gear fa-fw"></i> Reset password</a></li-->
						<li class="divider"></li>
						<li><a href="DeconnexionServlet"><i
								class="fa fa-sign-out fa-fw"></i> Sign up</a></li>
					</ul> <!-- /.dropdown-user --></li>
				<!-- /.dropdown -->
			</ul>
			<!-- /.navbar-top-links -->

			<div class="navbar-default navbar-static-side" role="navigation">
				<div class="sidebar-collapse">
					<ul class="nav" id="side-menu">
						<li><a href="#"><i class="fa fa-home fa-fw"></i> Home</a></li>
						<li>
							<%
								user = (User) request.getSession().getAttribute("user");
																							if(user.getType().equals("A")){
							%> <a href="ListUserServlet"><i class="fa fa-wrench fa-fw"></i>
								User management</a> <%
 	}
 %>
						</li>

					</ul>
					<!-- /#side-menu -->
				</div>
				<!-- /.sidebar-collapse -->
			</div>
			<!-- /.navbar-static-side -->
		</nav>

		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<h4 class="page-header">Schema management</h4>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="row">

				<div class="col-lg-12">
					<!-- /créer un profil -->
					<%
						user = (User) request.getSession().getAttribute("user");
						if (user.getType().equals("A")) {
					%>
					<a style="text-decoration: none;" href="#" data-toggle="modal"
						data-target="#myModal" name="creer" id="creer"
						onload="verif_bouton();"> <i class="fa fa-folder-open fa-fw"></i>Add
						a schema
					</a>
					<%
						}
					%>
					<a href="ConnexionServlet"><i class="fa fa-refresh fa-fw"></i>Refresh</a> 

					<!--input type="hidden" name="Creer" id="Creer" value="" /-->
					<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
						aria-labelledby="myModalLabel" aria-hidden="true">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal"
										aria-hidden="true">&times;</button>
									<h4 class="modal-title" id="myModalLabel">Add a schema</h4>
								</div>
								<form role="form" action="ProfileServlet" method="post">
									<div class="modal-body">

										<label>Database</label> <input class="form-control"
											type="text" name="Base" autofocus required> <label>Target
											Schema</label> <input class="form-control" type="text"
											name="Target_schema" autofocus required> <label>Target
											Password</label> <input class="form-control" type="text"
											name="Target_pwd" autofocus required><br/>
											<label>Imp Schema</label>&nbsp;
											<select name="impSchema" id="impSchema" required>
												<option value="-1">-- Choose the schema's type --</option>
												<%
													String[] impSchemas = CassiopaeDumpUtil.getApplicationValues(CassiopaeDumpConstant.KEY_PROPERTY_IMP_SCHEMA);
													for (String impSchema : impSchemas) {
												%>
												<option value="<%=impSchema%>"><%=impSchema%></option>
												<%
													}
												%>
											</select><br/><br/>
											<label>Oracle Version</label>&nbsp;
											<select name="dbVersion" required>
												<option value="-1">-- Choose the oracle's version --</option>
												<%
													String[] oracleVersions = CassiopaeDumpUtil.getApplicationValues(CassiopaeDumpConstant.KEY_PROPERTY_ORACLE_VERSION);
													for (String dbVersion : oracleVersions) {
												%>
												<option value="<%=dbVersion%>"><%=dbVersion%>g</option>
												<%
													}
												%>
											</select><br/><br/>

										<label>Version</label>&nbsp;
											<select name="appliVersion" required>
												<option value="-1">-- Choose the application's version --</option>
												<%
													String[] versions = CassiopaeDumpUtil.getApplicationValues(CassiopaeDumpConstant.KEY_PROPERTY_VERSION);
													for (String version : versions) {
												%>
												<option value="<%=version%>"><%=version%></option>
												<%
													}
												%>
											</select>

									</div>
									<div class="modal-footer">
										<button type="button" class="btn btn-default"
											data-dismiss="modal">Close</button>
										<input class="btn btn-success" type="submit"
											name="creerFolder" Value="create a profile" />
									</div>
								</form>
							</div>
							<!-- /.modal-content -->
						</div>
						<!-- /.modal-dialog -->
					</div>

				</div>
				<!-- /.col-lg-12 -->
			</div>


			<div class="row">
				<div class="col-lg-12">
					<h5 class="divider"></h5>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="row">
				<div class="col-lg-12">
					<div class="panel panel-default">
						<div class="panel-heading">List of schemas</div>
						<!-- /.panel-heading -->
						<div class="panel-body">
							<div>
								<table class="table" id="dataTables-example">
									<thead>
										<tr>
											<th>Name</th>
											<th>Info</th>
											<th>Begin Time</th>
											<th>End Time</th>
											<th>Actions</th>
											<th>Status</th>
											<th>
											<%
												user = (User) request.getSession().getAttribute("user");
																							if(user.getType().equals("A")){
											%>
											  Delete
											<%
												}
											%>
											</th>
										</tr>
									</thead>
									<tbody>
										<%
											List<Profile> profiles = ( ArrayList) request.getSession().getAttribute("LISTPROFIL");
                                            int i = 0;
                                            SimpleDateFormat sp = new SimpleDateFormat("dd/MM/yy HH:mm");
                                            for(Profile p : profiles){
										%>
										<tr class="defaut">
											<td><%=p.getNomProfile()%></td>
											<td><%=p.getImpSchema()+", "%><%=p.getDbVersion()+"g, "%><%=p.getAppliVersion()%></td>
											<td><%=p.getBeginHour() == null ?  "N/A" : sp.format( p.getBeginHour() )%></td>
											<td><%=p.getEndHour() == null ? "N/A" :  sp.format( p.getEndHour() )%></td>
											<td>

												<div class="col-lg-12">
													<!-- /créer un profil -->

													<a style="text-decoration: none;" href="#"
														data-toggle="modal" data-target="#myDumpFile" name="creer"
														id="creer" onload="verif_bouton();"
														onclick="UpdateIDProfile(<%=p.getId()%>)"><input class="btn btn-success"
														type="submit" name="runDump" Value="RUN" 
														<%
														if(p.getStatus()){
														%>
															disabled
														<%
														}
														%>
														/>
													</a>

												</div>


											</td>
											<td>
												<%
													if (p.getStatus()) {
												%> <img src="image/processing.gif" height="20%"
														width="20%" />
												<%
													}
												%>
 											</td>
											<td>
												<%
													user = (User) request.getSession().getAttribute("user");
																							if(user.getType().equals("A")){
												%>
												<a style="text-decoration: none;" 
												data-toggle="modal" data-target="#myDelete" name="creer" onclick="deleteProfile(<%=p.getId() %>);"
												id="creer" onload="verif_bouton();"><img alt="" src="image/delete.png" height="80%"
														width="40%" />
												</a>
												<%
													}
												%>
											</td>

										</tr>
										<%
                                            }
										%>
									</tbody>
								</table>
							</div>

						</div>
						<!-- /.panel-body -->
					</div>
					<!-- /.panel -->
				</div>
				<!-- /.col-lg-12 -->
			</div>



		</div>
		<!-- /#page-wrapper -->

	</div>
	<!-- /#wrapper -->

	<!-- Core Scripts - Include with every page -->
	<script src="js/jquery-1.10.2.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>

	<!-- Page-Level Plugin Scripts - Tables -->
	<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
	<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>

	<!-- SB Admin Scripts - Include with every page -->
	<script src="js/sb-admin.js"></script>

	<!-- Page-Level Demo Scripts - Tables - Use for reference -->
	<script>
    $(document).ready(function() {
        $('#dataTables-example').dataTable();
    });

    </script>

	<!-- Fenetre de lancement du dump DEBUT -->
	<div class="modal fade" id="myDumpFile" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content" >
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Run schema</h4>
				</div>
				<!-- 			<form role="form" action="DumpTaskServlet" method="post" enctype="multipart/form-data"> -->
				<form role="form" action="DumpTaskServlet" method="post">
					<div class="modal-body">

						<label>Source Schema</label> <input class="form-control"
							type="text" name="Source_schema" autofocus required> <label>Dump
							file</label>
						<div>

							<input class="form-control" type="file" name="FileDump"
								placeholder="Enter the dump file path... " required>
						</div>
						<input class="form-control" type="hidden" name="ProfileID"
							id="ProfileID"> <br />

						<fieldset>
							<label>Dump Type</label>
							<p>
								<input type="radio" name="importDmp" value="DUMP"><label>Dump</label>
								<br /> <input type="radio" name="importDmp" value="DATAPUMP"
									checked><label>Datapump</label>
							</p>
						</fieldset>
						<fieldset>
							<label>Dump Environment</label>
 							<p>
<!-- 								<input type="radio" name="environmentDmp" value="back" checked onclick="environmentDmpClick();"><label>Back</label>  -->
<!-- 								<input type="radio" name="environmentDmp" value="front" onclick="environmentDmpClick();"><label>Front</label> -->
								<input type="checkbox" id="environmentDmpBackFrontID" name="environmentDmp" value="true" onclick="environmentDmpClick();"><label>run also Back/Front</label>
								<div id="hiddenFormID" style="display:none;">
									<select name="impSchemaSelected" id="impSchemaSelected">
												<option value="-1">-- Choose an another target schema --</option>
												<%
													for (Profile p : profiles) {
												%>
												<option value="<%=p.getId()%>"><%=p.getNomProfile()+" - "%><%=p.getImpSchema()%></option>
												<%
													}
												%>
											</select>&nbsp;
									<input class="form-control" id="OtherSourceSchemaInput" type="text" name="OtherSourceSchemaInput" placeholder="Enter another source schema" ><br/> 									 
								</div>
							</p>
							
						</fieldset>
					</div>
					<div class="modal-footer">

						<input class="btn btn-success btn-lg" type="submit" name="dump"
							Value="Launch" />

						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

					</div>
				</form>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>

	<!-- Fenetre de lancement du dump FIN -->

	<!-- Fenetre de modification du password DEBUT -->
	<div class="modal fade" id="myResetPwd" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Reset your password</h4>
				</div>
				<form role="form" action="PasswordResetServlet" method="post">
					<div class="modal-body">

						<label>New password</label>
						<div>
							<input class="form-control" type="password" name="pwd" id="pwd"
								placeholder="New password " autofocus required>
						</div>

					</div>


					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

						<input class="btn btn-success" type="submit" name="pwdReset"
							Value="Reset" />

					</div>
				</form>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>

	<!--Fenetre de modification du password FIN -->
	
	<!-- Fenetre de suppression DEBUT -->
	<div class="modal fade" id="myDelete" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Delete</h4>
				</div>
				<form role="form" action="ActionServlet" method="get">
					<div class="modal-body">

						<label>Are you sure you want to remove this schema ?</label>
					
						<input class="form-control" type="hidden" name="deleteProfileID"
							id="deleteProfileID">
						<input class="form-control" type="hidden" name="action" value="supprimerSchema">
					</div>	
					<div class="modal-footer">
						<input class="btn btn-success" type="submit" name="delete"
							Value="Yes" />
						<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
						

					</div>
				</form>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>

	<!--Fenetre de suppression FIN -->


</body>


</html>
